<template>
    <div class="info-collect">
        <Crumb name="Unit property"> </Crumb>

        <div class="content">
            <el-button
                    type="primary"
                    @click="openAdd"
            >Add New Unit Property
            </el-button>
            <Search>

            </Search>
            <div class="table-wrapper">
                <el-table
                        :data="modelList"
                        border
                        stripe
                        style="width: 100%">

                    <el-table-column
                            prop="genre"
                            label="Genre"
                            width="180"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="fieldName"
                            label="Name"
                           >
                    </el-table-column>
                    <el-table-column
                            prop="fieldCode"
                            label="Code"
                    >
                    </el-table-column>
                    <!--<el-table-column label="Opr" >-->
                        <!--<template slot-scope="scope">-->
                            <!--<el-button-->
                                    <!--size="mini"-->
                                    <!--@click="openEdit(scope.row)">Modify-->
                            <!--</el-button>-->
                            <!--&lt;!&ndash;<el-button size="mini" type="warning" @click="showBind(scope.row)">Bind</el-button>&ndash;&gt;-->
                            <!--&lt;!&ndash;<el-button&ndash;&gt;-->
                                    <!--&lt;!&ndash;size="mini"&ndash;&gt;-->
                                    <!--&lt;!&ndash;type="danger"&ndash;&gt;-->
                                    <!--&lt;!&ndash;@click="console.log(scope.$index, scope.row)">Abandon&ndash;&gt;-->
                            <!--&lt;!&ndash;</el-button>&ndash;&gt;-->
                        <!--</template>-->
                    <!--</el-table-column>-->
                </el-table>
                <!--<div class="page">-->
                    <!--<el-pagination background-->
                                   <!--:page-size=10-->
                                   <!--@current-change="changePage"-->
                                   <!--layout="prev, pager, next"-->
                                   <!--:total="total"> </el-pagination>-->
                <!--</div>-->

            </div>

            <div class="modal-wrapper">
                <el-dialog
                        title="Unit Type"
                        top="10"
                        :visible.sync="dialogVisible"
                        width="80%"
                        >

                    <el-form :model="ruleForm"  ref="ruleForm" label-width="200px" class="demo-ruleForm">
                        <el-form-item label="Genre">
                            <el-select v-model="ruleForm.genre">
                                <el-option :value=0 label="Regular"></el-option>
                                <el-option :value=1 label="Select"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="Field Name">
                            <el-input v-model="ruleForm.fieldName"></el-input>
                        </el-form-item>
                        <el-form-item v-if="ruleForm.genre" label="Field Code">
                            <el-input v-model="ruleForm.fieldCode"></el-input>
                        </el-form-item>
                    </el-form>
                    <span slot="footer" class="dialog-footer">
                        <el-button @click="dialogVisible = false">Cancel</el-button>
                        <el-button type="primary" @click="submitForm">Confirm</el-button>
                    </span>
                </el-dialog>
            </div>
        </div>
    </div>
</template>

<script>
    import Crumb from '@/components/common/crumb'
    import Search from '@/components/common/search'
    import {getModelList,addModel} from "../../api/unit";

    export default {
        name: "info-collect",
        data() {
            return {
                part:[],
                model:[],
                ruleForm: {},
                modelList:[],
                dialogVisible:false
            }
        },
        created(){
            this.getModelList();
        },
        methods: {
            submitForm(){
                this.$refs.ruleForm.validate(async (valid) => {
                    if (valid) {
                            let {status} = await addModel(this.ruleForm.genre,this.ruleForm.fieldName,this.ruleForm.fieldCode);
                            if (status  === 0 ) {
                                this.$message({
                                    message:'Add Successfully',
                                    type:'success'
                                });
                               this.getModelList();
                                this.clear();
                                this.dialogVisible = false
                            }

                    } else {
                        return false;
                    }
                });
            },
            clear(){
                this.ruleForm= {};
            },
            openAdd(){
                this.clear();
                this.dialogVisible = true
            },
            openEdit(r){
                this.ruleForm = r;
                this.dialogVisible = true

            },
            async getModelList(){
                let {status,data} = await getModelList();
                if (status === 0 ) {
                    this.modelList = data
                }
            }
        },
        components: {
            Crumb, Search
        }
    }
</script>

<style scoped lang="scss">
    .info-collect {
        background: #f6;
        .content {
            text-align: left;
            padding: 20px 0;
            .table-wrapper {
                margin-top: 20px;
            }
            .page {
                text-align: center;
                margin-top: 10px;
            }
        }
    }
</style>